import 'package:flutter/material.dart';

///
/// ProjectName: nc_demo
/// Author: lizhi
/// CreateDate: 2025/3/21 17:46
/// Copyright: ©2025 NEW CORE Technology Co. Ltd. All rights reserved.
/// Description: 代码文件说明，markdown 格式
///
///
Future<T?> startLoading<T>(BuildContext context, Future<T> Function() f,
    {String? text}) async {
  showDialog(
    context: context,
    barrierDismissible: false, // 禁止通过点击外部区域关闭对话框
    builder: (BuildContext context) {
      return AlertDialog(
        content: Row(
          children: [
            CircularProgressIndicator(), // 加载指示器
            SizedBox(width: 20), // 添加一些间距
            Text(text ?? "加载中..."),
          ],
        ),
      );
    },
  );
  try {
    var res = await f.call();
    Navigator.of(context).pop(); // 关闭对话框
    return Future.value(res);
  } catch (err) {
    Navigator.of(context).pop(); // 关闭对话框
    throw err.toString();
  }
}

void toast(BuildContext context, String message) {
  ScaffoldMessenger.of(context).showSnackBar(
    SnackBar(
      content: Text(message),
      duration: Duration(seconds: 3), // 提示显示的时长
    ),
  );
}
